package com.magina.mq.controller;


import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Queue;
import javax.jms.Topic;
@Api(value = "/testActiveMq", description = "测试ActiveMq接口")
@RestController
@RequestMapping("/testActiveMq")
public class ActiveMqTestController {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    @Qualifier("myQueue")
    private Queue queue;

    @Autowired
    @Qualifier("myTopic")
    private Topic topic;

    @GetMapping("/testQueue")
    public String testQueue(){
        for (int i = 0; i < 10 ; i++){
            jmsMessagingTemplate.convertAndSend(queue, "activeMq send queue msg: count : "+i);
        }
        return "queue 发送成功";
    }

    @GetMapping("/testTopic")
    public String testTopic(){
        for (int i = 0; i < 10 ; i++){
            jmsMessagingTemplate.convertAndSend(topic, "activeMq send topic msg: count : "+i);
        }
        return "topic 发送成功";
    }
}